'''
Created on Apr 6, 2011

@author: riche
'''
import unittest
from ft.apps.gamma.util import bitmap


class Test(unittest.TestCase):


    def test_serialize(self):
        bm = bitmap.BitMap(8)
        bm.set(0)
        bm.set(7)
        self.assertEqual(bm.serialize(), '10000001')
        
    def test_bad_index(self):
        bm = bitmap.BitMap(8)
        self.assertRaises(IndexError, bm.set, 8)
        
    def test_set_string(self):
        bm = bitmap.BitMap(8, '01010101')
        self.assertEqual(bm.serialize(), '01010101')
        
    def test_set_string_size_mismatch(self):
        self.assertRaises(bitmap.SizeMismatchError, bitmap.BitMap, 5, '010101')
        
    def test_set_string_bad_val(self):
        self.assertRaises(bitmap.BadStringValError, bitmap.BitMap, 8, 'blahblah')

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_serialize']
    unittest.main()